<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Eventos</title>
    </h:head>
    <h:body onload="limpar()">
        <h:form id="formulario">
            <table>
                <tr>
                    <td>A:</td>
                    <td><h:inputText id="a" value="#{campos.campoA}" onchange="submit()" onkeypress="enviar(event)" valueChangeListener="#{campos.aChanged}"/></td>
                </tr>
                <tr>
                    <td>B:</td>
                    <td>
                        <h:selectOneListbox value="#{campos.selecionadoB}">
                            <f:selectItems value="#{campos.listaCamposB}" var="item"
                                           itemLabel="#{item}" itemValue="#{item}"/>
                        </h:selectOneListbox>
                    </td>
                </tr>
            </table>
        </h:form>

        <h:form style="margin-top: 50px">
            <h:panelGrid id="date" columns="2">
                <f:event type="postValidate" listener="#{data.validarData}"/>

                (dia)
                <h:inputText id="dia" value="#{data.dia}" size="2" required="true"/>

                (mes)
                <h:inputText id="mes" value="#{data.mes}" size="2" required="true"/>

                (ano)
                <h:inputText id="ano" value="#{data.ano}" size="4" required="true"/>
            </h:panelGrid>
            <h:commandButton onclick="submit()" value="Validar"/>
        </h:form>
    <script type="text/javascript">
        function limpar(){
            document.getElementById("formulario:a").value = "";
            document.getElementById("formulario:a").focus();
        }

        function enviar(event){
            //keyCode 13 = enter
            if (event.keyCode==13){
                submit();
            }
        }
    </script>

    </h:body>
</html>